home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Toolbox / IconUtilCheck / IconUtilCheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-07  |  2.1 KB  |  82 lines  |  [TEXT/KAHL]

  1. /****
  2.     According to the Tech Note OV - 16, "Inside Macintosh: More Macintosh 
  3.     Toolbox, page 5-7, specifies that the gestaltIconUtilitiesAttr - 'icon'
  4.     gestalt selector can be used to determine whether the icon utilities
  5.     are present under System 7.x.   Note that this selector is included in
  6.     the GestaltEqu files.  It turns out that this selector is not
  7.     implemented until System Software v7.1.2.  To check for the existence of
  8.     these utilities, use the TrapAvailable code to check for the 
  9.     _IconDispatch, (0xABC9) trap.  The TrapAvailable code is presented in
  10.     Inside Macintosh VI 3-8, and as sample code in many of the snippets
  11.     on the Developer CD."
  12.  
  13.     This snippet shows how to determine whether the Icon Utilities
  14.     are available.
  15.         
  16.     Written by Virginia (Ginny) McCulloh
  17.     Apple Developer Technical Support
  18.     August 1995, Cupertino, CA
  19.     Copyright 1995, Apple Computer, Inc.
  20.  
  21.     This runs under Think C 7.0.4, CodeWarrior 6,
  22.      and MPW 3.3.1 with the Universal Headers.
  23. ****/
  24.  
  25. #include <stdio.h>
  26. #include <Types.h>
  27. #include <OSUtils.h>
  28. #include <GestaltEqu.h>
  29.  
  30. #ifndef __TRAPS__
  31. #include <Traps.h>
  32. #endif
  33.  
  34. #define    TrapMask        0x0800
  35.  
  36.  
  37. Boolean TrapAvailable(short theTrap);
  38. short NumToolboxTraps(void);
  39. TrapType GetTrapType(short theTrap);
  40.     
  41. short NumToolboxTraps(void)
  42. {
  43.     if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E,ToolTrap))
  44.         return 0x0200;
  45.     else
  46.         return 0x0400;
  47. }
  48.  
  49. TrapType GetTrapType(short theTrap)
  50. {
  51.     if ((theTrap & TrapMask) > 0)
  52.         return ToolTrap;
  53.     else
  54.         return OSTrap;
  55. }
  56.  
  57. Boolean TrapAvailable(short theTrap)
  58. {
  59.     TrapType tType;
  60.     Boolean isAvail;
  61.     
  62.     tType = GetTrapType(theTrap);
  63.     if (tType == ToolTrap)
  64.         {
  65.             theTrap &= 0x07FF;
  66.             if (theTrap >= NumToolboxTraps())
  67.                 theTrap = _Unimplemented;
  68.         }
  69.     
  70.     isAvail = NGetTrapAddress(theTrap, tType) != NGetTrapAddress(_Unimplemented, ToolTrap);
  71.     return isAvail;
  72. }
  73.  
  74. main()
  75. {
  76.     printf("Testing for presence of Icon Utilities\n");
  77.     if (TrapAvailable(_IconDispatch))
  78.         printf("Icon Utilities are available\n");
  79.     else
  80.         printf("Icon Utilities are not available\n");
  81. }
  82.